package com.mutual.reins.interf.service.impl;

import com.mutual.reins.interf.entity.ReinsInterFlog;
import com.mutual.reins.interf.entity.ReinsOverEndorDto;
import com.mutual.reins.interf.entity.ReinsStatusDto;
import com.mutual.reins.interf.service.IGeneratePrppDangerUnitService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
/**
 * @author zjl
 */
@Service
@Transactional(rollbackFor = Exception.class)
@Slf4j
public class GeneratePrppDangerUnitServiceImpl implements IGeneratePrppDangerUnitService {
    /**
     * 批单核批通过调再保生成再保批单数据
     * @param reinsOverEndorDto 核批通过送再保数据
     * @return 生成数据状态信息
     */
    @Override
    public ReinsStatusDto generateEndorDangerUnit(ReinsOverEndorDto reinsOverEndorDto) {
        log.info("批单审核通过调入时间：" +LocalDate.now());
        ReinsStatusDto reinsStatusDto = new ReinsStatusDto();
        ReinsInterFlog reinsInterfLogDto = new ReinsInterFlog();
        try {
            reinsStatusDto.setCerTiNo(reinsOverEndorDto.getEndorseNo());
            reinsStatusDto.setCerTiType(reinsOverEndorDto.getCertiType());
            reinsStatusDto.setStatus("Y");
            // 初始化再保审核通过日志表
            reinsInterfLogDto.setCerTiType(reinsOverEndorDto.getCertiType());
            reinsInterfLogDto.setCerTiNo(reinsOverEndorDto.getEndorseNo());
            reinsInterfLogDto.setProposalNo(reinsOverEndorDto.getProposalNo());
            reinsInterfLogDto.setPolicyNo(reinsOverEndorDto.getPolicyNo());
            reinsInterfLogDto.setProposalNo(reinsOverEndorDto.getProposalNo());
            reinsInterfLogDto.setApplyNo(reinsOverEndorDto.getApplyNo());
            reinsInterfLogDto.setEndorNo(reinsOverEndorDto.getEndorseNo());
            reinsInterfLogDto.setOperatorCode(reinsOverEndorDto
                    .getUnderwriteCode());
            reinsInterfLogDto.setOperatorName(reinsOverEndorDto
                    .getUnderwriteName());
            reinsInterfLogDto.setOperatorDate(reinsOverEndorDto
                    .getUnderWriteEndDate());
            // 日志表插入时通过状态默认为不成功
            reinsInterfLogDto.setRecordFlag("0");
            // 生成再保日志表，中间表，再保危险单位，分批试算，分批单，分批复核信息
            this.overwriteAndGenReinsData(
                    reinsOverEndorDto, reinsInterfLogDto);
        } catch (Exception e) {
            reinsStatusDto.setStatus("N");
            e.printStackTrace();
            // throw e;
        }
        log.info("批单审核通过调出时间：" +LocalDate.now());
        return reinsStatusDto;
    }

    /**
     * 核批生成正式批单逻辑
     * @param reinsOverEndorDto 核批送再保信息
     * @param reinsInterfLogDto 核批批单日志信息
     */
    private void overwriteAndGenReinsData(ReinsOverEndorDto reinsOverEndorDto, ReinsInterFlog reinsInterfLogDto) {

    }


}
